package com.gao.list;

import com.gao.domain.Student;

import java.util.ArrayList;

/**
 * @Author: ShanYuqing
 * @Version: v1.0
 */
public class ArrayListTest4 {
    /*
            需求：定义一个方法，方法接收一个集合对象（泛型为Student）
                    方法内部将年龄低于18的学生对象找出
                    并且存入新集合对象，方法返回集合
     */
    public static void main(String[] args) {
        ArrayList<Student> list = new ArrayList<>();
        ArrayList<Student> list2 = new ArrayList<>();
        Student stu1 = new Student("张三",85);
        Student stu2 = new Student("张",15);
        Student stu3 = new Student("三",18);
        Student stu4 = new Student("张三22",58);
        list.add(stu1);
        list.add(stu2);
        list.add(stu3);
        list.add(stu4);
        for (int i = 0; i < list.size(); i++) {
            Student stu = list.get(i);
            if(stu.getAge()<18){
                System.out.println(stu.getName()+"----"+stu.getAge());
                list2.add(stu);
            }
        }
        for (int i = 0; i < list2.size(); i++) {
            Student stu = list2.get(i);
            System.out.println(stu.getName()+"--------"+stu.getAge());
        }
    }
}
